import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import WindiCSS from "vite-plugin-windicss";
import cesium from "vite-plugin-cesium";

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    cesium(),
    WindiCSS(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
      imports: ["vue", "vue-router", "pinia"],
      dts: true,
      eslintrc: {
        enabled: false,
      },
      // 添加类型声明目录
      dirs: ["./src/stores/**"],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
      dts: true,
    }),
  ],
  resolve: {
    alias: {
      "@": resolve(__dirname, "src"),
      "@/": resolve(__dirname, "src/") + "/",
    },
  },
  server: {
    port: 3000,
    open: true,
    cors: true,
    proxy: {
      // 代理所有 /api 开头的请求到后端服务器
      "/api": {
        target: 'http://192.168.3.243:18610',
        // target: "http://192.168.2.253:18610",
        // target: 'http://10.0.66.27:18610',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
      // 代理录像查询请求到录像服务器
      "/playback": {
        target: 'http://192.168.3.231:25080',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/playback/, ""),
      },
    },
  },
  build: {
    target: "es2015",
    outDir: "dist",
    assetsDir: "assets",
    sourcemap: false,
    minify: "terser",
    rollupOptions: {
      output: {
        manualChunks: {
          vendor: ["vue", "vue-router", "pinia"],
          elementPlus: ["element-plus"],
        },
      },
    },
  },
});
0